<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- tweetsearch.qdoc -->
  <title>Qt Quick Demo - Tweet Search | Qt 5.14</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="index.html">Qt 5.14</a></td><td >Qt Quick Demo - Tweet Search</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.14.2 Reference Documentation</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<h1 class="title">Qt Quick Demo - Tweet Search</h1>
<span class="subtitle"></span>
<pre class="qml">

  <span class="comment">/****************************************************************************
  **
  ** Copyright (C) 2017 The Qt Company Ltd.
  ** Contact: https://www.qt.io/licensing/
  **
  ** This file is part of the examples of the Qt Toolkit.
  **
  ** $QT_BEGIN_LICENSE:BSD$
  ** Commercial License Usage
  ** Licensees holding valid commercial Qt licenses may use this file in
  ** accordance with the commercial license agreement provided with the
  ** Software or, alternatively, in accordance with the terms contained in
  ** a written agreement between you and The Qt Company. For licensing terms
  ** and conditions see https://www.qt.io/terms-conditions. For further
  ** information use the contact form at https://www.qt.io/contact-us.
  **
  ** BSD License Usage
  ** Alternatively, you may use this file under the terms of the BSD license
  ** as follows:
  **
  ** &quot;Redistribution and use in source and binary forms, with or without
  ** modification, are permitted provided that the following conditions are
  ** met:
  **   * Redistributions of source code must retain the above copyright
  **     notice, this list of conditions and the following disclaimer.
  **   * Redistributions in binary form must reproduce the above copyright
  **     notice, this list of conditions and the following disclaimer in
  **     the documentation and/or other materials provided with the
  **     distribution.
  **   * Neither the name of The Qt Company Ltd nor the names of its
  **     contributors may be used to endorse or promote products derived
  **     from this software without specific prior written permission.
  **
  **
  ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  ** &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&quot;
  **
  ** $QT_END_LICENSE$
  **
  ****************************************************************************/</span>

  import QtQuick 2.0
  import &quot;content&quot;
  import &quot;content/tweetsearch.mjs&quot; as Helper

  <span class="type"><a href="../qtquick/qml-qtquick-rectangle.html">Rectangle</a></span> {
      <span class="name">id</span>: <span class="name">main</span>
      <span class="name">width</span>: <span class="number">320</span>
      <span class="name">height</span>: <span class="number">480</span>
      <span class="name">color</span>: <span class="string">&quot;#d6d6d6&quot;</span>

      property <span class="type"><a href="../qtqml/qml-int.html">int</a></span> <span class="name">inAnimDur</span>: <span class="number">250</span>
      property <span class="type"><a href="../qtqml/qml-int.html">int</a></span> <span class="name">counter</span>: <span class="number">0</span>
      property <span class="type"><a href="../qtqml/qml-var.html">var</a></span> <span class="name">idx</span>
      property <span class="type"><a href="../qtqml/qml-var.html">var</a></span> <span class="name">ids</span>

      <span class="name">Component</span>.onCompleted: <span class="name">ids</span> <span class="operator">=</span> new <span class="name">Array</span>()

      <span class="keyword">function</span> <span class="name">idInModel</span>(id)
      {
          <span class="keyword">for</span> (var j = 0; <span class="name">j</span> <span class="operator">&lt;</span> <span class="name">ids</span>.<span class="name">length</span>; j++)
              <span class="keyword">if</span> (<span class="name">ids</span>[<span class="name">j</span>] <span class="operator">===</span> <span class="name">id</span>)
                  <span class="keyword">return</span> <span class="number">1</span>
          <span class="keyword">return</span> <span class="number">0</span>
      }

      <span class="type">TweetsModel</span> {
          <span class="name">id</span>: <span class="name">tweetsModel</span>
          <span class="name">onIsLoaded</span>: {
              <span class="name">console</span>.<span class="name">debug</span>(<span class="string">&quot;Reload&quot;</span>)
              <span class="name">idx</span> <span class="operator">=</span> new <span class="name">Array</span>()
              <span class="keyword">for</span> (var i = 0; <span class="name">i</span> <span class="operator">&lt;</span> <span class="name">tweetsModel</span>.<span class="name">model</span>.<span class="name">count</span>; i++) {
                  var id = <span class="name">tweetsModel</span>.<span class="name">model</span>.<span class="name">get</span>(<span class="name">i</span>).<span class="name">id</span>
                  <span class="keyword">if</span> (!<span class="name">idInModel</span>(<span class="name">id</span>))
                      <span class="name">idx</span>.<span class="name">push</span>(<span class="name">i</span>)
              }
              <span class="name">console</span>.<span class="name">debug</span>(<span class="name">idx</span>.<span class="name">length</span> <span class="operator">+</span> <span class="string">&quot; new tweets&quot;</span>)
              <span class="name">main</span>.<span class="name">counter</span> <span class="operator">=</span> <span class="name">idx</span>.<span class="name">length</span>
          }
      }

      <span class="type"><a href="../qtqml/qml-qtqml-timer.html">Timer</a></span> {
          <span class="name">id</span>: <span class="name">timer</span>
          <span class="name">interval</span>: <span class="number">500</span>; <span class="name">running</span>: <span class="name">main</span>.<span class="name">counter</span>; <span class="name">repeat</span>: <span class="number">true</span>
          <span class="name">onTriggered</span>: {
              main.counter--;
              var id = <span class="name">tweetsModel</span>.<span class="name">model</span>.<span class="name">get</span>(<span class="name">idx</span>[<span class="name">main</span>.<span class="name">counter</span>]).<span class="name">id</span>
              var item = <span class="name">tweetsModel</span>.<span class="name">model</span>.<span class="name">get</span>(<span class="name">main</span>.<span class="name">counter</span>)
              <span class="name">mainListView</span>.<span class="name">add</span>( { &quot;statusText&quot;: <span class="name">Helper</span>.<span class="name">insertLinks</span>(<span class="name">item</span>.<span class="name">text</span>, <span class="name">item</span>.<span class="name">entities</span>),
                                  &quot;twitterName&quot;: <span class="name">item</span>.<span class="name">user</span>.<span class="name">screen_name</span>,
                                  &quot;name&quot; : <span class="name">item</span>.<span class="name">user</span>.<span class="name">name</span>,
                                  &quot;userImage&quot;: <span class="name">item</span>.<span class="name">user</span>.<span class="name">profile_image_url</span>,
                                  &quot;source&quot;: <span class="name">item</span>.<span class="name">source</span>,
                                  &quot;id&quot;: <span class="name">id</span>,
                                   &quot;uri&quot;: <span class="name">Helper</span>.<span class="name">insertLinks</span>(<span class="name">item</span>.<span class="name">user</span>.<span class="name">url</span>, <span class="name">item</span>.<span class="name">user</span>.<span class="name">entities</span>),
                                  &quot;published&quot;: <span class="name">item</span>.<span class="name">created_at</span> } );
              <span class="name">ids</span>.<span class="name">push</span>(<span class="name">id</span>)
          }
      }

      <span class="type"><a href="../qtquick/qml-qtquick-listview.html">ListView</a></span> {
          <span class="name">id</span>: <span class="name">mainListView</span>
          <span class="name">anchors</span>.fill: <span class="name">parent</span>
          <span class="name">delegate</span>: <span class="name">TweetDelegate</span> { }
          <span class="name">model</span>: <span class="name">ListModel</span> { <span class="name">id</span>: <span class="name">finalModel</span> }

          <span class="name">add</span>: <span class="name">Transition</span> {
              <span class="type"><a href="../qtquick/qml-qtquick-numberanimation.html">NumberAnimation</a></span> { <span class="name">property</span>: <span class="string">&quot;hm&quot;</span>; <span class="name">from</span>: <span class="number">0</span>; <span class="name">to</span>: <span class="number">1.0</span>; <span class="name">duration</span>: <span class="number">300</span>; <span class="name">easing</span>.type: <span class="name">Easing</span>.<span class="name">OutQuad</span> }
              <span class="type"><a href="../qtquick/qml-qtquick-propertyaction.html">PropertyAction</a></span> { <span class="name">property</span>: <span class="string">&quot;appear&quot;</span>; <span class="name">value</span>: <span class="number">250</span> }
          }

          <span class="name">onDragEnded</span>: <span class="keyword">if</span> (<span class="name">header</span>.<span class="name">refresh</span>) { <span class="name">tweetsModel</span>.<span class="name">reload</span>() }

          <span class="type">ListHeader</span> {
              <span class="name">id</span>: <span class="name">header</span>
              <span class="name">y</span>: -<span class="name">mainListView</span>.<span class="name">contentY</span> <span class="operator">-</span> <span class="name">height</span>
          }

          <span class="name">footer</span>: <span class="name">ListFooter</span> { }

          <span class="keyword">function</span> <span class="name">clear</span>() {
              <span class="name">ids</span> <span class="operator">=</span> new <span class="name">Array</span>()
              <span class="name">model</span>.<span class="name">clear</span>()
          }

          <span class="keyword">function</span> <span class="name">add</span>(obj) {
              <span class="name">model</span>.<span class="name">insert</span>(<span class="number">0</span>, <span class="name">obj</span>)
          }

          signal <span class="type">autoSearch</span>(string type, string str) <span class="comment">// To communicate with Footer instance</span>
      }
  }

</pre>
